package poject.service.Impl;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import poject.mapper.StudentdbMapper;
import poject.pojo.ExcelUtil;
import poject.pojo.Studentdb;
import poject.service.StudentdbService;

@Service
public class StudentServiceImpl implements StudentdbService {
    @Resource
    private StudentdbMapper studentdbMapper;
    private int count=1;
    @Override
    public void insertdb(InputStream in, MultipartFile file)throws Exception {
    	//输出上传的文件名
        System.out.println(file.getOriginalFilename());
        //将文件的内容保存到List数组里
            List<List<Object>> listob = ExcelUtil.getBankListByExcel(in,file.getOriginalFilename());
            //新建的自定义List数组用于保存数据
            List<Studentdb> salaryList = new ArrayList<Studentdb>();
            //遍历listob数据，把数据放到List中
            for (int i = 0; i < listob.size(); i++) {
                List<Object> ob = listob.get(i);
                Studentdb studentdb = new Studentdb();
                String id=String.valueOf(ob.get(1));
                String name=String.valueOf(ob.get(2));
                String classname=String.valueOf(ob.get(3));
                String note=String.valueOf(ob.get(4));;
                studentdb.setCount(count);
                studentdb.setId(id);
                studentdb.setName(name);
                studentdb.setClassname(classname);
                studentdb.setNote(note);
                salaryList.add(studentdb);
                count++;
                System.out.println(studentdb);
            }
            //批量插入数据库
        studentdbMapper.insertdb(salaryList);
            
    }
}